var Log = require('../framework/log');

function GetAllBattlePlayerHandler(session,msg){
    var channel = app.getChannelService().getChannel("world");
    if(channel){
        var playerIds = channel.playerManager.getAllPlayerId();
        var results = [];
        for(var i in playerIds){
            var playerId = playerIds[i];
            var player = channel.playerManager.getPlayer(playerId);
            var rate = 0;
            var total = player.win + player.lost + player.drop;
            if(total > 0){
                rate = player.win/total;
            }
            results.push([player.name,player.swordLevel,player.wuli,player.win,player.lost,player.drop,rate,player.id]);
        }
        Log.debug("GetAllBattlePlayerHandler OK,player = %s",session.getPlayer().getPlayerId());
        return {ret:true,"results":results};
    }else{
        Log.debug("GetAllBattlePlayerHandler Fail, Channel World not exists, player = %s",session.getPlayer().getPlayerId());
        return {ret:false};
    }
}

module.exports = GetAllBattlePlayerHandler;